package com.windowes.weichang.controller.platform;

import com.windowes.weichang.access.AccessLimit;
import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.dto.*;
import com.windowes.weichang.pojo.Demand;
import com.windowes.weichang.pojo.DemandCustomerPayFlow;
import com.windowes.weichang.pojo.DemandShopPayFlow;
import com.windowes.weichang.service.DemandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/6/1 上午8:41
 * @description:
 *
 **/
@RestController
@Api(description = "用户需求相关API")
@RequestMapping("demand")
public class DemandController {

    @Autowired
    DemandService demandService;

    @AccessLimit(manageUser = true)
    @ApiOperation(value = "保存/更新 需求", notes = "非平台管理人员调用")
    @PostMapping("saveOrUpdate")
    public ServerResponse saveOrUpdate(@RequestBody Demand demand) {
        return demandService.saveOrUpdate(demand);
    }

    //    @AccessLimit
    @ApiOperation(value = "业务员更新用户", notes = "业务员更新用户信息")
    @PostMapping("updateCustomerInfo")
    public ServerResponse updateCustomerInfo(@RequestBody DemandUserInfo demandUserInfo) {
        return demandService.updateCustomerInfo(demandUserInfo);
    }


    /**
     * @param
     * @return
     */
    @AccessLimit
    @ApiOperation(value = "需求列表", notes = "【App】客户需求列表")
    @GetMapping("list")
    public ServerResponse listForCustomer(String type, String keyword, @RequestParam(value = "status", required = false) Short status, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                          @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return demandService.listForCustomer(status, pageNo, pageSize, keyword, type);
    }

    /**
     * @param
     * @return
     */
    @AccessLimit
    @ApiOperation(value = "需求列表", notes = "平台")
    @GetMapping("manage/list")
    public ServerResponse listForPlatform(String type, String keyword, Short status, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                          @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return demandService.listForPlatform(status, pageNo, pageSize, keyword, type);
    }

    /**
     * @param
     * @return
     */
    @AccessLimit(manageUser = true)
    @ApiOperation(value = "订单结算", notes = "平台")
    @GetMapping("manage/balance/list")
    public ServerResponse listForPlatformBalance(String type, String keyword, Short status, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                                 @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return demandService.listForPlatformBalance(status, pageNo, pageSize, keyword, type);
    }


    /**
     * @param
     * @return
     */
    @AccessLimit
    @ApiOperation(value = "需求列表", notes = "【App】商户")
    @GetMapping("manage/shop/list")
    public ServerResponse listForShopkeeper(String type, String keyword, Short status, Integer shopId, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                            @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return demandService.listForShopkeeper(status, shopId, pageNo, pageSize, keyword, type);
    }

    @ApiOperation(value = "获取店铺下所有订单", notes = "")
    @GetMapping("manage/shop")
    public ServerResponse listDemandByShopId(Integer id) {
        return demandService.listDemandByShopId(id);
    }

    @AccessLimit(shopUser = true)
    @ApiOperation(value = "获取客户", notes = "")
    @GetMapping("manage/user")
    public ServerResponse listDemandByUserId(Integer id) {
        return demandService.listDemandByUserId(id);
    }

    @AccessLimit
    @ApiOperation(value = "添加/更新 跟进需求", notes = "【App】商户/业务员上传客户详细需求")
    @PostMapping("addOrUpdate/item")
    public ServerResponse addDemandItem(@RequestBody DemandItemDto dto) {
        return demandService.addDemandItem(dto);
    }


    @ApiOperation(value = "更新 需求状态", notes = "【App】普通用户")
    @PostMapping("updateStatus")
    public ServerResponse updateOrderStatus(@RequestBody DemandStatusDto demandStatus) {
        return demandService.updateOrderStatus(demandStatus);
    }


    /**
     * @param
     * @return
     */
    @ApiOperation(value = "获取需求详情", notes = "")
    @GetMapping("item")
    public ServerResponse item(Integer demandId) {
        return demandService.item(demandId);
    }

    @ApiOperation(value = "设置预约时间", notes = "")
    @AccessLimit(shopUser = true)
    @PostMapping("setTime")
    public ServerResponse setTime(@RequestBody AppointParam appointParam) {
        return demandService.setTime(appointParam);
    }

    /**
     * 确认到达
     *
     * @param arrivalInfo
     * @return
     */
    @ApiOperation(value = "确认到达", notes = "")
    @AccessLimit
    @PostMapping("confirmArrival")
    public ServerResponse confirmArrival(@RequestBody ConfirmArrivalInfo arrivalInfo) {
        return demandService.confirmArrival(arrivalInfo);
    }

    /**
     * 确认到达
     *
     * @return
     */
    @ApiOperation(value = "设置生产中", notes = "")
    @AccessLimit
    @PostMapping("producing")
    public ServerResponse producing(Integer id, Integer prodicingStep) {
        return demandService.producing(id, prodicingStep);
    }


    @ApiOperation(value = "创建方案", notes = "")
    @AccessLimit
    @PostMapping("createProject")
    public ServerResponse createProject(@RequestBody DemandProjectDto projectDto) {
        return demandService.createProject(projectDto);
    }

    @ApiOperation(value = "用户评价", notes = "用户评价")
    @AccessLimit
    @PostMapping("doComment")
    public ServerResponse doComment(@RequestBody DemandCommentDto projectDto) {
        return demandService.doComment(projectDto);
    }

    @ApiOperation(value = "上传施工图片")
    @AccessLimit
    @PostMapping("addInstallCases")
    public ServerResponse addInstallCases(@RequestBody ProjectDoneDto projectDto) {
        return demandService.addInstallCases(projectDto);
    }

    @ApiOperation(value = "安装确认到达")
    @AccessLimit
    @PostMapping("confirmInstallArrival")
    public ServerResponse confirmInstallArrival(@RequestBody ConfirmArrivalInfo projectDto) {
        return demandService.confirmInstallArrival(projectDto);
    }

    @ApiOperation(value = "预约安装")
    @AccessLimit
    @PostMapping("appointInstall")
    public ServerResponse appointInstall(@RequestBody AppointParam projectDto) {
        return demandService.appointInstall(projectDto);
    }


    @ApiOperation(value = "生产完成")
    @AccessLimit
    @PostMapping("produceDone")
    public ServerResponse produceDone(Integer id) {
        return demandService.produceDone(id);
    }

    @ApiOperation(value = "确认施工方案并支付")
    @AccessLimit
    @PostMapping("confirmProjectAndPay")
    public ServerResponse confirmProjectAndPay(Integer demandId) {
        return demandService.confirmProjectAndPay(demandId);
    }

    @ApiOperation(value = "分配业务员")
    @AccessLimit
    @PostMapping("dispatchSalesman")
    public ServerResponse dispatchSalesman(@RequestBody DispatchParam dispatchParam) {
        return demandService.dispatchSalesman(dispatchParam);
    }

    @ApiOperation(value = "分配店铺")
    @AccessLimit
    @PostMapping("dispatchShop")
    public ServerResponse dispatchShop(@RequestBody DispatchParam dispatchParam) {
        return demandService.dispatchShop(dispatchParam);
    }


    @ApiOperation(value = "结尾款")
    @AccessLimit
    @PostMapping("completeAll")
    public ServerResponse completeAll(@RequestBody PayInfo payInfo) {
        return demandService.completeAll(payInfo);
    }


    @AccessLimit
    @ApiOperation(value = "取消订单", notes = "客户")
    @PostMapping("cancle")
    public ServerResponse cancle(@RequestBody CancleDTO cancleDTO) {
        return demandService.cancle(cancleDTO);
    }

    @AccessLimit(shopUser = true)
    @ApiOperation(value = "取消订单", notes = "商户")
    @PostMapping("cancleForShop")
    public ServerResponse cancleForShop(@RequestBody CancleDTO cancleDTO) {
        return demandService.cancleForShop(cancleDTO);
    }

    @AccessLimit
    @PostMapping("addShopBalance")
    public ServerResponse addShopBalance(@RequestBody DemandShopPayFlow demandCustomerPayFlow) {
        return demandService.addShopBalance(demandCustomerPayFlow);
    }

}
